<template>
  <div class="attraction">
    <h2 class="txt">景点推荐</h2>
    <div class="content">
      <ul>
        <li v-for="item in attractionList" :key="item.id">
          <div class="img">
            <img :src="item.picture" alt="" style="width: 275px; height: 185px; display: block;">
          </div>
          <div class="info">
            <div class="title">
              <p>{{item.title}}</p>
            </div>
            <div class="bottom">
              <div class="username">{{item.username}}</div>
              <div class="thumb">{{item.name}}</div>
            </div>
          </div>

        </li>
      </ul>
    </div>
    <br>
    <pagination :total="total"></pagination>
    <el-divider></el-divider>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination.vue";
import { reqAttractionList,reqRecommendAttraction } from "@/api/index";

export default {
  components: { Pagination },
  name: "Attraction",
  data() {
    return {
      attractionList: [],
      total: 0,
    };
  },
  methods: {
    getDetail() {
      this.$router.push({
        name: "login",
      });
    },
  },
  mounted() {
    const userId = localStorage.getItem("userId")
    if (userId == null) {
      reqAttractionList().then((res) => {
        console.log("res", res);
        this.attractionList = res.data.records;
        this.total = this.attractionList.length;
      });
    }else{
      reqRecommendAttraction({'userId': userId}).then((res) => {
        console.log("res", res);
        this.attractionList = res.data;
        this.total = this.attractionList.length;
      });
    }
  },
};
</script>

<style scoped>
.attraction {
  text-align: center;
}
.txt {
  /* text-align: center; */
  display: block;
  /* width: 100%; */
}

.info {
  padding: 18px;
  border: 1px;
  text-align: left;
}

.title {
  width: 237px;
  height: 48px;
  margin-top: 0px;
  font-size: 16px;
  font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Heiti SC", "WenQuanYi Micro Hei",
    sans-serif;
  overflow: hidden;
  line-height: 24px;
  text-align-last: left;
}

p {
  margin: 0;
  font-style: 24px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.username {
  width: 130.34px;
  height: 24px;
  margin-top: 16px;
  display: inline-block;
  font-size: 14px;
}

.thumb {
  height: 24px;
  margin-top: 16px;
  /* 行内块元素右靠 */
  float: right;
  font-size: 12px;
}

.img {
  width: 275px;
  height: 185px;
  display: block;
}

.title {
  display: block;
  text-align: center;
}

.content {
  display: flex;
}

ul {
  margin: auto;
  padding: 0;
  border: 0;
  text-align: center;
}

li {
  width: 275px;
  height: 300px;
  margin-left: 60px;
  margin-top: 20px;
  display: inline-block;
  /* vertical-align: top; */
  text-align: center;
  border: 1px solid #ececec;
}

li span {
  display: block;
}

li:nth-child(4n + 1) {
  margin-left: 0px;
}
</style>